<template>
   <div class="update-container">
          <div class="update-top-container">
              <el-page-header @back="goBack" content="商品页面">
              </el-page-header>
          </div>
      <el-form  ref="form" status-icon  :rules="rules" :model="form" label-width="80px">
        <el-form-item label="商品代碼" prop="username">
          <el-input v-model="form.username" style="width:90%"></el-input>
        </el-form-item>
        
         <el-form-item label="商品名稱" prop="password">
          <el-input  v-model="form.password" style="width:90%"></el-input>
        </el-form-item>

        <el-form-item label="商品類別" prop="password">
          <el-input  v-model="form.password" style="width:90%"></el-input>
        </el-form-item>

        <el-form-item label="價格" prop="password">
          <el-input  v-model="form.password" style="width:90%"></el-input>
        </el-form-item>

        <el-form-item label="單位" prop="password">
          <el-input  v-model="form.password" style="width:90%"></el-input>
        </el-form-item>
        

        <div class="button-container">
          
            <el-button type="primary" @click="submit()" >提交</el-button>
          
        </div>
      </el-form>
    </div>
</template>

<script>
export default {
    name:'addUser',
    data() {
      return {
         choice:'新增用戶',
         IsOk:'',
         form: {
            username: '',
            password: '',
          },
         rules:{
          
         }
      
     }
    },
    methods: {
        async submit(){
          let that=this;
          //update....
          
         if(this.$route.query.do=='add'){
          //add
          console.log('add??');
          await this.$axios.get("http://localhost:8081/addUser?userName="+this.form.username+"&passWord="+this.form.password)
            .then((result) => {
                //console.log(result.data);
                that.$router.push({path:'/homepage/UserInfo',query:{status:result.data}})
                return;
            }).catch((err) => {
              
            });
           }
          else
          {
           await this.$axios.get("http://localhost:8081/updateUser?userId="+this.$route.query.userId+"&userName="+this.form.username+"&passWord="+this.form.password)
            .then((result) => {
                //console.log(result.data);
                that.$router.push({path:'/homepage/UserInfo',query:{status:result.data}})
              
               
            }).catch((err) => {
              
            });
          }
        },
        goBack(){
          this.$router.push('/homepage/goodsInfo');
        },
        load(){
          //console.log(this.$route);
          if(this.$route.query)
          {
            this.form.username=this.$route.query.userName;
            this.form.password=this.$route.query.passWord;
          }
        }
    },
    mounted() {
      this.load();
    },

}
</script>

<style>

   .el-form-item__content{
       width: 400px;
   }
   .update-container{
     width: 80%;
     padding: 20px;
     
   }
   .update-top-container{
     width: 100%;
     height: 50px;
     padding-left: 20px;
   }
</style>